package application;

import application.dao.DBService;
import application.dao.entity.EnrollUser;
import application.dao.entity.Manager;
import application.dao.entity.User;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextField;

import java.util.Date;

public class Athlete_enroll_controller extends BaseController {

    @FXML
    public TextField p_name;
    @FXML
    public TextField p_realName;
    @FXML
    public TextField p_mobile;
    @FXML
    public TextField p_idCard;
    @FXML
    public TextField p_address;
    @FXML
    private Button change_info;

    @FXML
    private Menu menu_enroll;

    @FXML
    private Menu menu_main;

    @FXML
    private MenuItem menu_informations_announcements;

    @FXML
    private MenuItem menu_informations_news;

    @FXML
    private Button enroll_yes;

    @FXML
    private Menu menu_person;

    @FXML
    private Menu menu_scores;

    @FXML
    void onButton_enroll_yes(ActionEvent event) {
        System.out.println("fix");
        EnrollUser user = getUserByLabel();
        DBService.addEnrollUser(user);
    }

    private EnrollUser getUserByLabel() {
        EnrollUser user = new EnrollUser();
        User loginUser = Global.loginUser;
        user.setUserName(loginUser.getUserName());
        user.setRealName(loginUser.getRealName());
        user.setSex(loginUser.getSex());
        user.setIdCard(loginUser.getIdCard());
        user.setApplicationTime(new Date());
        return user;
    }

    @FXML
    void onButton_change_info(ActionEvent event) {
        System.out.println("onButton_change_info");
        EnrollUser user = getUserByLabel();
        DBService.updateEnrolUser(user);
    }

    @FXML
    void onCheckMenu_main(ActionEvent event) {

    }

    @FXML
    void onCheckMenu_person(ActionEvent event) {

    }

    @FXML
    void onCheckMenu_enroll(ActionEvent event) {

    }

    @FXML
    void onCheckMenu_scores(ActionEvent event) {

    }

    @FXML
    void onCheckMenu_informations_announcements(ActionEvent event) {

    }

    @FXML
    void onCheckMenu_informations_news(ActionEvent event) {

    }

    @Override
    public javafx.stage.Stage setStage(javafx.stage.Stage stage) {
        stage = stage;
        return stage;
    }

    @Override
    public void init() {
        initShow();
    }

    private void initShow() {
        User loginUser = Global.loginUser;
        p_name.setText(loginUser.getIdCard());
        p_name.setText(loginUser.getUserName());
        p_mobile.setText(loginUser.getTelNumber());
        p_realName.setText(loginUser.getRealName());
        p_address.setText(loginUser.getHomeAddress());
    }
}